import math


def vector_disturb(mp, ap):
    if 0 <= ap <= 90:
        return mp * math.sin(ap * math.pi / 180), -mp * math.cos(ap * math.pi / 180)
    if 90 <= ap <= 180:
        return mp * math.cos((ap - 90) * math.pi / 180), mp * math.sin((ap - 90) * math.pi / 180)
    if 180 <= ap <= 270:
        return mp * -math.sin((ap - 180) * math.pi / 180), mp * math.cos((ap - 180) * math.pi / 180)
    if 270 <= ap <= 360:
        return mp * -math.cos((ap - 270) * math.pi / 180), -mp * math.sin((ap - 270) * math.pi / 180)


def vector_spawn(spl_x, spl_y):
    ma = 0
    mm = 0
    if spl_x == 0 or spl_y == 0:
        if spl_y == 0 and spl_x != 0:
            if spl_x > 0:
                ma, mm = 90, spl_x
            if spl_x < 0:
                ma, mm = 270, -spl_x
        if spl_x == 0 and spl_y != 0:
            if spl_y < 0:
                ma, mm = 0, -spl_y
            if spl_y > 0:
                ma, mm = 180, spl_y
        if spl_x == 0 and spl_y == 0:
            ma, mm = 0, 0
    if spl_x > 0 and spl_y < 0:
        ma = math.atan(spl_x / -spl_y) * 180 / math.pi
        mm = math.sin(ma * math.pi / 180) ** -1 * spl_x
    if spl_x > 0 and spl_y > 0:
        ma = math.atan(spl_y / spl_x) * 180 / math.pi
        mm = math.sin(ma * math.pi / 180) ** -1 * spl_y
        ma += 90
    if spl_x < 0 and spl_y > 0:
        ma = math.atan(-spl_x / spl_y) * 180 / math.pi
        mm = math.sin(ma * math.pi / 180) ** -1 * -spl_x
        ma += 180
    if spl_x < 0 and spl_y < 0:
        ma = math.atan(-spl_y / -spl_x) * 180 / math.pi
        mm = math.sin(ma * math.pi / 180) ** -1 * -spl_y
        ma += 270
    return ma, mm


class Vector:
    def __init__(self, m, a):
        # 设置向量的大小（magnitude），角度（angle）
        self.magnitude = m
        self.angle = a

    def express(self):
        # 输出向量
        print("Vector Surface:[" + str(self.magnitude) + "/" + str(self.angle) + "]")

    def move_angle(self, da):
        # 角度偏移
        self.angle += da
        if self.angle < 0:
            self.angle = 360 + self.angle
        self.angle = self.angle % 360

    def vector_mix(self, m2, a2):
        # 新的向量加法运算（平行四边形定则）
        x1, y1 = vector_disturb(self.magnitude, self.angle)
        x2, y2 = vector_disturb(m2, a2)
        ra, rm = vector_spawn(x1 + x2, y1 + y2)
        self.magnitude = rm
        self.angle = ra


def main():
    print("========Debug of Vector========")
    dbVector = Vector(100, 30)
    dbVector2 = Vector(200, 150)
    dbVector.express()
    dbVector2.express()
    dbVector.vector_mix(dbVector2.magnitude, dbVector2.angle)
    dbVector.express()
    print("===============================")


main()
